package com.kakaxi.mybilibili.adapter.pager;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.kakaxi.mybilibili.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 基础碎片的滑动布局适配器
 * Created by kakaxi on 16/11/24.
 */

public class BaseFragmentPagerAdapter<T extends BaseFragment> extends FragmentPagerAdapter {

    private List<T> mFragmentList;

    public BaseFragmentPagerAdapter(FragmentManager fm, List<T> fragmentList) {
        super(fm);
        if (fragmentList != null) {
            mFragmentList = fragmentList;
        } else {
            mFragmentList = new ArrayList<>();
        }
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mFragmentList.get(position).getTitle();
    }
}
